<?php
require_once(dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR ."core".DIRECTORY_SEPARATOR."functions.php");
core::getResource("Model.Event");

class RoleController extends baseController
{
	private $roleId;
	private $role;
	public function __construct($roleId)
	{
		$this->roleId = $roleId;
		$this->role = new Role($roleId);
	}

	public function getTitle()
	{
		return $this->role->title;
	}
    
    public function getDescription()
    {
        return $this->role->description;
    }
    
    public function getActivityId()
    {
        return $this->role->activity;
    }
    
    public function getActivityName()
    {
        return (new Activity((int) $this->role->activity))->title;
    }
    
    public function getEventId()
    {
        return (new Activity((int) $this->role->activity))->event;
    }
    
    public function getEventName()
    {
        $eventId = (new Activity((int) $this->role->activity))->event;
        return (new Event((int) $eventId))->eventName;
    }
    
    public function getStartAndEndTimes()
	{
		return $this->role->startTime." to ".$this->role->endTime;
	}

	public function getStartAndEndDates()
	{
		return $this->role->startDate." to ".$this->role->endDate;
	}
    
    public function getPositions()
    {
        return $this->role->positions;
    }
    
    public function getSkills()
    {
        return $this->role->skills;
    }
    public function getPaid()
    {
        return $this->role->payRate;
    }
    
	public static function getAllRoles($startDate)
	{
		return Role::getRolesByDate($startDate);
	}
    
    public function roleExists()
	{
		if(Role::exists($this->roleId))
		{
			return true;
		}
		else
		{
			return false;
		}
	}

    public static function delete($roleId)
    {
        $db = new dbConn();
        $db->query("DELETE FROM applied WHERE role=$roleId");
        $db->query("DELETE FROM role WHERE roleId=$roleId");
    }

    public static function deleteAppliedSpecific($role,$person,$add=false)
    {
        $db = new dbConn();
        if($add)
        {
            $db->query("DELETE FROM applied WHERE role=$role AND person=$person AND applied!='accepted'");
        }
        else
        {
            $db->query("DELETE FROM applied WHERE role=$role AND person=$person");
        }
    }
}

?>